package uz.edo.app.admin.core.header;

import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import uz.edo.app.admin.Login;
import uz.edo.app.admin.core.AdminSession;
import uz.edo.app.admin.departmentPages.DepartmentListView;
import uz.edo.app.admin.organizationPages.OrganisationListView;
import uz.edo.app.admin.privilegePages.PrivilegeListView;
import uz.edo.app.admin.rolePages.RoleListView;
import uz.edo.app.admin.userPages.UserListView;
import uz.edo.db.bean.User;
import uz.edo.utils.Constants;

/**
 * Created by IntelliJ IDEA.
 * User: said
 * Date: 1/16/12
 * Time: 12:02 PM
 * To change this template use File | Settings | File Templates.
 */
public class AdminHeader extends Panel implements Constants{

    public WebMarkupContainer headerMenu;
    private User user;
    private AdminSession session;

    public AdminHeader(String id) {
        super(id);
        session = (AdminSession)getSession();
        user = session.getUser();
        WebMarkupContainer topPanel = new WebMarkupContainer("topPanel");
        topPanel.add(new Label("user_lang", "uz"));
        topPanel.add(new Label("user",  user.getLastName() + " " + user.getFirstName()));
        topPanel.setVisible(true);
        add(topPanel);
        headerMenu = new WebMarkupContainer("headerMenu");
        headerMenu.add(new BookmarkablePageLink("organisation", OrganisationListView.class).setVisible(user.isPrivileged(SU) || user.isPrivileged(SYSADMIN)));
        headerMenu.add(new BookmarkablePageLink("department", DepartmentListView.class).setVisible(user.isPrivileged(SU) || user.isPrivileged(SYSADMIN)));
        headerMenu.add(new BookmarkablePageLink("user", UserListView.class));
        headerMenu.add(new BookmarkablePageLink("role", RoleListView.class));
        headerMenu.add(new BookmarkablePageLink("privilege", PrivilegeListView.class).setVisible(user.isPrivileged(SU)));
        Link logout = new Link("signout") {

            @Override
            public void onClick() {
                session.setUser(null);
                setResponsePage(Login.class);
            }
        };
        headerMenu.add(logout);
        add(headerMenu);
    }
}
